package com.example.mysaat.handle_utils;

import android.util.Log;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class HandlerFile {
    private static final int BUFFER_SIZE = 128;
    private static final String TAG = "HandlerFile";
    public static String getFileInfo(String path) {
        File mFile;
        FileReader mFileReader = null;
        if (path == null) {
            return null;
        }
        mFile = new File(path);

        try {
            mFileReader = new FileReader(mFile);
            char data[] = new char[BUFFER_SIZE];
            int charCount;
            String status[];
            try {
                charCount = mFileReader.read(data);
                status = new String(data, 0, charCount).trim().split("\n");
                Log.i(TAG, "status[] = " + charCount + "  >>> status[0] =  " + status[0]);
                return status[0];
            } catch (IOException e) {
                Log.e(TAG, "read data error : ", e);
            }
        } catch (FileNotFoundException e) {
            Log.e(TAG, "can't find file : " + path, e);
        } finally {
            if (mFileReader != null) {
                try {
                    mFileReader.close();
                } catch (IOException e) {
                    Log.e(TAG, "getFileInfo exception", e);
                }
            }
            mFileReader = null;
        }
        return null;
    }
}
